<?php 


/**
* 
*/
class RentingController extends Zend_Controller_Action
{
	
	function init()
	{
		$this->model = new Application_Model_Renting();
		$this->form = new Application_Form_Datacenter();
		$this->request=$this->getRequest();
	}

    

	
	public function indexAction()
	{
		
        $this->_helper->breadcrumbs->addStep('Seguimiento Renting','');
        $this->view->headTitle('Seguimiento Renting');

		$rows = $this->model->getRentings();
        
        
		$this->view->rows =$this->_helper->prepareRows($rows);

	}
	
	public function insertarAction()
    {
    	$this->_helper->insertar( $this->form, $this->_helper);
	}
	
	public function editarAction()
    {
    	$this->_helper->editar( $this->form, $this->_helper);
	}
	
	public function borrarAction()
	{
	   	$this->_helper->viewRenderer->setNoRender(TRUE);
    	$this->_helper->layout->disableLayout();
        
		$id=$this->request->getParam('id');
		$this->model->deleteById($id);
        
       	echo $this->view->json(array('status'=>'ok'));
        

	}
	
	
	function prepareValuesToTr($row)
	{
		$row['dc']=($row['dc']) ? 'SI' : 'NO' ;
		$row['co']=($row['co']) ? 'SI' : 'NO' ;
		$row['ct']=($row['ct']) ? 'SI' : 'NO' ;
		return $row;
	}
	
	
	
	function prepareValuesToDb1()
	{
		$data=$this->form->getValues();
		
		
		if($this->view->actionName=='insertar'){
			$id=$this->model->insert($data);
		}else{
			$id=$this->request->getParam('id');
			$this->model->updateById($data,$id);
		}
		
		$row=$this->model->getRowById($id);
		return $this->prepareValuesToTr($row);
	}
	
}


